#include <windows.h>
#include <winsock2.h>
#include "TCPConnection.h"
//
TCPConnection::TCPConnection(SOCKET sck) : _sck(sck) {
}
//
TCPConnection::~TCPConnection() {
	::shutdown(_sck, SD_BOTH);
	::closesocket(_sck);
}
//
bool TCPConnection::send(const char* buffer, size_t& size) {
	int nBytes = ::send(_sck, buffer, (int)size, 0);
	if (nBytes == SOCKET_ERROR) {
		size = 0;
		return false;
	} else {
		size = (size_t)nBytes;
		return true;
	}
}
//
bool TCPConnection::receive(char* buffer, size_t& size) {
	int nBytes = ::recv(_sck, buffer, (int)size, 0);
	if (nBytes == SOCKET_ERROR || nBytes == 0) {
		size = 0;
		return false;
	} else {
		size = (size_t)nBytes;
		return true;
	}
}
//